package com.spark.mooc.ch2_scala.part02_objectOrientedProgramming

/**
 * @description:
 * @time: 2020/11/24 14:27
 * @author: lhy
 */
class Car(name:String) {
    def info(): Unit ={
        println("Car name is " + name)
    }
}
object Car{
    def apply(name: String): Car = new Car(name)    //调用伴生类Car的构造方法
}
object MyTestApply{
    def main(args: Array[String]): Unit = {
        val myCar = Car("BMW")  //调用伴生对象中的apply方法
        myCar.info()
    }
}
